﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;

namespace Framework.Mvc.Util
{
    public static class ContollerExtension
    {
        /// <summary>
        /// Extension methods for the controller to allow jsonp.
        /// </summary>
        /// <param name="controller">The controller.</param>
        /// <param name="data">The data.</param>
        /// <returns></returns>
        public static JsonpResult Jsonp(this Controller controller, object data)
        {
            return new JsonpResult { Data = data };
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="controller"></param>
        /// <param name="total"></param>
        /// <param name="rows"></param>
        /// <returns></returns>
        public static EasyUIGridJsonResult EasyUIGridJson(this Controller controller, int total, object rows)
        {
            var result = new EasyUIGridJsonResult(total, rows);
            return result;
        }

        /// <summary>
        /// Success
        /// </summary>
        /// <param name="controller"></param>
        /// <param name="success"></param>
        /// <param name="message"></param>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static SuccessJsonpResult Success(this Controller controller, bool success, string message = null, object obj = null)
        {
            return new SuccessJsonpResult(success, message, obj);
        }

        /// <summary>
        /// Success
        /// </summary>
        /// <param name="controller"></param>
        /// <param name="success"></param>
        /// <param name="message"></param>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static SuccessJsonpResult Success(this Controller controller, int code, string message = null, object obj = null)
        {
            return new SuccessJsonpResult(code, message, obj);
        }
    }
}
